 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page session="true" import="servlets.*" %>
<%@ page session="true" import="classes.*" %>
<%@ page session="true" import="beans.*" %>
<%@ page session="true" import="java.sql.ResultSet" %>
<%  	session = request.getSession(true); %>
<%@page import="java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html class="js" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sistema de Noticias</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<%@ include file="inc_head.jsp" %>  
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
	jQuery('#load').fadeOut(1000);
	}
);   

tinyMCE.init({ 
	// General options
	mode : "textareas", 
	theme : "advanced",
	plugins : "pagebreak,style,layer,advhr,advlink,emotions,contextmenu,paste,visualchars,nonbreaking,xhtmlxtras",

	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,|,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,|,forecolor,backcolor",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom", 
	theme_advanced_resizing : true,

	// Example content CSS (should be your site CSS)
	content_css : "css/example.css",

	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "js/template_list.js",
	external_link_list_url : "js/link_list.js",
	external_image_list_url : "js/image_list.js",
	media_external_list_url : "js/media_list.js",

	// Replace values for the template plugin
	template_replace_values : {
		username : "Some User",
		staffid : "991234"
	}
});



</script>

</head>
<body>  
<div id="page"> 
  <div id="wrapper"> 
    <div id="header"> <a href="?pg=index"><img src="index_arquivos/logo.png" alt="" id="logo"></a> 
           <h2><a href="Home"></a></h2> 
      <div class="slogan" style="color:#ffffff"></div> 
    </div> 
    <div id="left-col"> 
    
   <%@ include file="inc_menutop.jsp" %>   

      
      <!-- /nav -->  
      <div id="content"> 
        <div class="dbx-box" id="block-block"> 
          <div> 
            <% if (request.getParameter("msg_sucesso") != null) { %> 
            <div id="msg_sucesso"><% out.print(request.getParameter("msg_sucesso")); %></div>
            <% } %>
              <% if (request.getParameter("msg_erro") != null) { %> 
            <div id="msg_erro"><% out.print(request.getParameter("msg_erro")); %></div>
            <% } %> 

			<div style="float:left">
            	<h1>Noticias</h1>
            </div
            <div id="load" style="display:block;float:left;padding-left:30px;">
			    <img src="images/loading.gif" width="10%" height="10%" />
			</div> 
			<div style="clear:both"></div>
  
  
				<%  	List<Noticia> noticias  = (List<Noticia>)session.getValue("noticias"); %> 
				    
				<% for(int i = 0; i < noticias.size(); i++) {
					Noticia noticia = (Noticia)noticias.get(i);  
					String url_imagem = "";
					String url_video = "";
					
					NoticiaDAO noticiaDAO = new NoticiaJDBC();
					List<Imagem> imagens = noticiaDAO.findAllImagens(noticia.getId());
					
					if(imagens != null && imagens.size() > 0) {
						for(int j = 0; j < imagens.size(); j++) {
							Imagem imagem = imagens.get(j);
							url_imagem += "<div style=\"float:right;margin-left:4px\" ><img src=\""+imagem.getUrl()+"\" width=\"100px\"></div>";
						} 
					} 		

 
					List<Video> videos = noticiaDAO.findAllVideos(noticia.getId());
					 
					if(videos != null && videos.size() > 0) {
						for(int j = 0; j < videos.size(); j++) {
							Video video = videos.get(j);
							String url_vid = video.getUrl(); 
							int ind = url_vid.indexOf("v=");
							String id_vid = url_vid.substring(2+ind);
	 						
							 
							url_video = url_video + "<div style=\"float:right;margin-left:4px\" >" +
							"<object width=\"100px\" height=\"80px\">" +
							"<param name=\"movie\" value=\"http://www.youtube.com/v/" + id_vid + "&hl=pt-br&fs=1&disablekb=1\">" +
							"</param>" +
							"<param name=\"allowFullScreen\" value=\"true\"></param>" +
							"<param name=\"allowscriptaccess\" value=\"always\"></param>" +
							"<embed src=\"http://www.youtube.com/v/" + id_vid + "&hl=pt-br&fs=1&disablekb=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"100\" height=\"80\">" +
							" 	</embed></object>"+ 
									 "</div>"; 		
						} 
					} 
         		
         	 	%>  
            
                    <ul>
                    
                        <li>   
                        	<% if(url_imagem != ""){ out.print(url_imagem);} %>
                        	<% if(url_video != ""){ out.print(url_video);} %>                        	
                        	<strong><a href="NoticiasVer?id=<%  out.print(noticia.getId()); %>"><%  out.print(noticia.getTitulo()); %></a></strong> (<%  out.print(noticia.data_ddmmyyyy()); %>)   
 							
 	                      	<a href="NoticiasEdit?id=<%  out.print(noticia.getId()); %>"><img src="css/itheme/images/mini-edit.gif" border="0"></a>   
                        	<a href="NoticiasDelete?id=<%  out.print(noticia.getId()); %>"><img src="css/itheme/images/mini-trash.gif" border="0"></a>
                         	[<a href="#" onClick="MyWindow=window.open('NoticiasImagens?id=<% out.print(noticia.getId()); %>','NoticiasImagens','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=550,height=600'); return false;">imagens</a>]
                        	[<a href="#" onClick="MyWindow=window.open('NoticiasVideos?id=<% out.print(noticia.getId()); %>','NoticiasVideos','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=550,height=600'); return false;">videos</a>]
							<div style="clear:both"></div> 
                        </li>
                   </ul> 
                    
                <%    
				}
				%>   

     
     <br /><br />
     



			<h2>Adicionar Noticia</h2>	
			
			  <form action="NoticiasAdd" method="post">	 
				                  
              <p>
              <span class="titulo_01">
              <strong>Titulo</strong>:<br />
              <input type="text" name="titulo" id="titulo" style="width:280px"  />
              <br />   
              
              <strong>Categoria:</strong><br />
              </span>
                  <span class="titulo_01">
                  <select name="id_categoria" style="width:280px">
                    <option></option>
  
					<%  	List<Categoria> categorias  = (List<Categoria>)session.getValue("categorias"); %> 

					<% for(int i = 0; i < categorias.size(); i++) {
						Categoria categoria = (Categoria)categorias.get(i); 
					%>  
                    <option value="<%=categoria.getId() %>"><%= categoria.getNome() %></option>
                    <%
                    }
                    %>
                  </select>
                  <br />
                  
			    <strong>Corpo da not&iacute;cia:</strong><br />
			      </span>
			    <strong>
			     <textarea name="corpo" id="corpo" style="width:500px"  rows="21"></textarea>
			      </strong>                </p>
			<p><span class="titulo_01"><strong>Tags:</strong> 
			    <input type="text" name="tags" id="tags" style="width:490px" value="" />
				</span><span class="titulo_01"><small>(Separado por v&iacute;rgula: internet, web, google)</small>

			  <br />   
              <strong>Data</strong>:<br />
              <input type="text" name="data" id="data" style="width:80px" maxlength="20" value="" onKeyPress="return(formatTyping(this,event,'data'))" onKeyPress="return(formatTyping(this,event,'data'))" >
              <img src="css/calendario.gif" id="trigger_data" onmouseover="return escape('Selecione a data')" style="cursor: pointer;" title="Selecione a data" /> 
               
               <script type="text/javascript">
							  Calendar.setup(
								{
								  inputField  : "data",      
								  ifFormat    : "%d-%m-%Y",   
								  button      : "trigger_data"     
								}
							  );
				</script>
 
              
              <br />   
              <p>
	              <span class="botao_comum" style="float:left">
	            	  <input type="submit" value="Enviar" />
	              </span>           
              </p>
				
				</form>



		</div> 
        </div> 
      </div> 
      <div id="footer">&nbsp;</div> 
    </div> 
    
    
   <%@ include file="inc_menu.jsp" %>  



    <hr class="hidden"> 
  </div> 
</div> 
</body>
</html>
